local huchi = fk.CreateSkill {

  name = "joyex__huchi",

  tags = {  },

}



huchi:addEffect("active", {
  name = "joyex__huchi",
  anim_type = "drawcard",
  prompt = "#joyex__huchi-draw",
  can_use = function(self, player)
    return player:getMark("@joyex__huchi") > 0 and player:usedSkillTimes(huchi.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local n = player:getMark("@joyex__huchi")
    player.room:setPlayerMark(player,"@joyex__huchi",0)
    if not player.dead then
      player:drawCards(n,huchi.name)
    end
  end,
})

huchi:addEffect(fk.CardEffectCancelledOut, {
  name = "#joyex__huchi",
  anim_type = "drawcard",
  events = {fk.CardEffectCancelledOut, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      return target == player and player:hasSkill(huchi.name) and data.card.trueName == "slash"
    else
      return target == player  and player:hasSkill(huchi.name) and player:getHandcardNum() < 2
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      player.room:addPlayerMark(player,"@joyex__huchi",1)
    else
      player:drawCards( 2 - player:getHandcardNum(),huchi.name)
    end
  end,
})
huchi:addEffect(fk.TurnEnd, {
  name = "#joyex__huchi",
  anim_type = "drawcard",
  events = {fk.CardEffectCancelledOut, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      return target == player and player:hasSkill(huchi.name) and data.card.trueName == "slash"
    else
      return target == player  and player:hasSkill(huchi.name) and player:getHandcardNum() < 2
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      player.room:addPlayerMark(player,"@joyex__huchi",1)
    else
      player:drawCards( 2 - player:getHandcardNum(),huchi.name)
    end
  end,
})

return huchi